#include <bits/stdc++.h>
// 2025/06/14
// tag:
// Author: Forever
using namespace std;
using int64 = int64_t;

const int N = 2501;
int n, k, s[N], node[N], p[N];
double val[N], f[N][N];
vector<int> v[N];

void dfs(int x){
    node[x]++, f[x][1] = val[x];
    for (int y : v[x]){
        dfs(y);
        node[x] += node[y];
        for (int j = min(node[x], k + 1); j >= 1; j--){
            for (int t = 0; t <= min(j - 1, node[y]); t++){
                f[x][j] = max(f[x][j], f[x][j - t] + f[y][t]);
            }
        }
    }
}

bool check(double x){
    memset(node, 0, sizeof(node));
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= k + 1; j++)
            f[i][j] = -1e9;
    for (int i = 1; i <= n; i++)
        val[i] = p[i] - s[i] * x;
    dfs(0);
    return f[0][k + 1] >= 0;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> k >> n;
    for (int i = 1; i <= n; i++){
        int x;
        cin >> s[i] >> p[i] >> x;
        v[x].push_back(i);
    }
    double l = 0, r = 1e9;
    while (r - l > 1e-4){
        double mid = (l + r) / 2;
        if (check(mid)) l = mid;
        else r = mid;
    }
    cout << fixed << setprecision(3) << l << endl;
    return 0;
}